/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * PanelPole.java
 *
 * Created on 2011-05-14, 09:21:26
 */

package App.widoki;

import App.kontrolery.IObslugaWyboruPola;
import App.kontrolery.KontrolerPrzegladajKontenery;
import java.awt.Color;
import javax.swing.JLabel;
import skladowisko.Pole;

/**
 *
 * @author Krzysiek
 */
public class PanelPole extends javax.swing.JPanel {

    /** Creates new form PanelPole */
    private static final Color KOLOR_PUSTE = Color.white;
    private static final Color KOLOR_NIEPELNE = Color.blue;
    private static final Color KOLOR_PELNE = Color.black;
    private static final Color KOLOR_KLIKNIETE = Color.RED;

    private Color kolor;

    private Pole pole;
    private IObslugaWyboruPola nadzorca;

    private boolean klikniete = false;

    public PanelPole(Pole pole, int width, int height)
    {
        this.pole = pole;
        this.setBounds(0,0,width, height);
        initComponents();

        if(pole.getZawartoscPola().isPuste()){
            this.setBackground(KOLOR_PUSTE);
            kolor = KOLOR_PUSTE;
        }
        else if(pole.getZawartoscPola().isPelne())
        {
            this.setBackground(KOLOR_PELNE);
            kolor = KOLOR_PELNE;
        }
        else
        {
            this.setBackground(KOLOR_NIEPELNE);
            kolor = KOLOR_NIEPELNE;
        }       
    }  
    
    public void ustawKolor(boolean klikniete)
    {
        if(klikniete)
        {
            this.setBackground(Color.red);
        }
        else
        {
            this.setBackground(kolor);
        }

        this.repaint();
    }

    public Pole getPole()
    {
        return this.pole;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                formMouseClicked(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                formMouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                formMouseExited(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 400, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 300, Short.MAX_VALUE)
        );
    }// </editor-fold>//GEN-END:initComponents

    private void formMouseEntered(java.awt.event.MouseEvent evt)//GEN-FIRST:event_formMouseEntered
    {//GEN-HEADEREND:event_formMouseEntered
        if(!klikniete)
        {
            int r = kolor.getRed();
            int g = kolor.getGreen();
            int b = kolor.getBlue();

            //Color wjechano = new Color(r+10, g+10, b+10);
             Color wjechano = Color.CYAN;
            this.setBackground(wjechano);
            this.repaint();
        }
        nadzorca.obslugujWejscie(pole);
    }//GEN-LAST:event_formMouseEntered

    private void formMouseExited(java.awt.event.MouseEvent evt)//GEN-FIRST:event_formMouseExited
    {//GEN-HEADEREND:event_formMouseExited
        if(!klikniete)
        {
            this.setBackground(kolor);
            this.repaint();
        }

        nadzorca.obslugujWyjscie(pole);
    }

    void ustawObserwatora(KontrolerPrzegladajKontenery nadzorca)
    {
        this.nadzorca = nadzorca;
    }//GEN-LAST:event_formMouseExited

    private void formMouseClicked(java.awt.event.MouseEvent evt)//GEN-FIRST:event_formMouseClicked
    {//GEN-HEADEREND:event_formMouseClicked
        this.setBackground(KOLOR_KLIKNIETE);
        nadzorca.obslugujWybranie(this);
        this.klikniete = true;
    }//GEN-LAST:event_formMouseClicked

    public void setKlikniete(boolean klikniete)
    {
        this.klikniete = klikniete;
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    // End of variables declaration//GEN-END:variables

}
